// var shareData = {
//     title: title,
//     desc: desc,
//     link:  shareUrl,
//     imgUrl: imgUrl,
//     type: 'link',
//     dataUrl: '',
//     success: function () {
//         alert('分享成功！');
//     },
//     fail: function () {
//         alert("分享失败，请重试！");
//     },
//     cancel: function () {
//         alert("您取消了分享");
//     }
// };

initWxShare();

function initWxShare() {
    if (!window.wx) {
        return;
    }
    var regParm = window.location.href.split('#')[0];//后台签名的url一定是使用jssdk的当前页面的完整url除去'#'部分
    $.ajax({
        url: "/wxRedirct?url=" + regParm,
        type: "GET",
        success: function (datas) {
            if ("" != datas) {
                var data = eval("(" + datas + ")");
                wx.config({
                    debug: false,
                    appId: data.appId,
                    timestamp: data.timestamp,
                    nonceStr: data.nonceStr,
                    signature: data.signature,
                    jsApiList: ['scanQRCode','onMenuShareTimeline', 'onMenuShareAppMessage', 'onMenuShareQQ'],
                    success: function (el) {
                    }, fail: function (el) {
                    }
                });
                wx.ready(function () {
                    wx.checkJsApi({
                        jsApiList: ['onMenuShareTimeline', 'onMenuShareAppMessage', 'onMenuShareQQ'],
                        success: function (res) {
                            var shareData = {
                                title: "在家也可定做寿司啦",
                                desc: "寿司大厨精心为您定做，全城可配送",
                                link: "http://www.ztyweb.cn/tc",
                                imgUrl: "https://ws2.sinaimg.cn/large/006tNc79gy1fidn2fctwkj30ls0f7dj3.jpg",
                                type: 'link',
                                dataUrl: '',
                                success: function () {
                                    alert('分享成功！');
                                },
                                fail: function () {
                                    alert("分享失败，请重试！");
                                },
                                cancel: function () {
                                    alert("您取消了分享");
                                }
                            };
                            wx.onMenuShareAppMessage(shareData);
                            wx.onMenuShareTimeline(shareData);
                            wx.onMenuShareQQ(shareData);
                        },
                        fail: function () {
                            alert('您的微信当前版本不支持此分享功能!');
                        }
                    });
                });
            }

        }
    });

};

$("#testScan").on('click',function (event) {
    wx.scanQRCode({
        needResult: 1, // 默认为0，扫描结果由微信处理，1则直接返回扫描结果，
        scanType: ["qrCode","barCode"], // 可以指定扫二维码还是一维码，默认二者都有
        success: function (res) {
            var result = res.resultStr; // 当needResult 为 1 时，扫码返回的结果
            alert(result)
        }
    });
});
